<?
include "../include/database.php";

if($_GET['deleteclicksub'])
{
	$id = $_GET['id'];
	mysql_query("DELETE FROM subartikelen WHERE id = '". $id ."'");
	
	print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"1; URL=admin_article.php?list=1\">";
	print "Wijziging succesvol.<br>";
	print "<blink>U wordt doorgestuurd...</blink>";
}

if($_GET['deleteclick'])
{
	$id = $_GET['id'];
	mysql_query("DELETE FROM artikelen WHERE id = '". $id ."'");
	
	print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"1; URL=admin_article.php?list=1\">";
	print "Wijziging succesvol.<br>";
	print "<blink>U wordt doorgestuurd...</blink>";
}


if($_GET['editsub'])
{
	if($_GET['start'])
	{
		$id				= $_GET['id'];
		$omschrijving 	= $_POST['omschrijving'];
		$kopje 			= $_POST['kopje'];
	
		$query = " UPDATE  `subartikelen` SET  `omschrijving` =  '".$omschrijving."',
		`kopje` =  '".$kopje."' WHERE  `id` =".$id." LIMIT 1";
		
		mysql_query($query);
		
		print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"1; URL=admin_article.php?list=1\">";
		print "Wijziging succesvol.<br>";
		print "<blink>U wordt doorgestuurd...</blink>";
	}
	
	$subarticleid = $_GET['id'];
	
	$query = mysql_query("SELECT * FROM subartikelen WHERE id = '" . $subarticleid ."'");
	while($result = mysql_fetch_object($query))
	{	
		//html form hier met print !
		?>
 		<form method="post" action="admin_article.php?editsub=1&start=1&id=<? print $result->id; ?>" name="klant_wijzig">
		
        <table width="100%" border="0">
			<tr>
				<td width="25%"><b>Id:</b></td>
				<td width="75%"><input name="id" type="text" value="<? print $subarticleid; ?>" size="5" disabled></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Omschrijving:</b></td>
				<td><input name="omschrijving" type="text" value="<? print $result->omschrijving; ?>"></td>
			</tr>
            <tr>
				<td><b>Subartikel:</b></td>
				<td><input name="kopje" type="text" value="<? print $result->kopje; ?>"></td>
			</tr>
            <tr>
				<td></td>
				<td><input name="submit" type="submit" value="Edit"></td>
			</tr>
		</table>
</form>
        <?
	}
}

if($_GET['editart'])
{
	if($_GET['start'])
	{
		$id = $_GET['id'];
		$omschrijving = $_POST['omschrijving'];
		$bedrag = $_POST['bedrag'];
		$kopje = $_POST['subartikel'];
		$image = $_POST['image'];
	
		$query = mysql_query("SELECT * FROM subartikelen WHERE kopje = '" . $kopje ."'");
		while($result = mysql_fetch_object($query))
		{
			$idsub = $result->id;
		}
		
		$query = "UPDATE  `artikelen` SET  `omschrijving` =  '".$omschrijving."',
			`bedrag` =  '".$bedrag."',
			`subartikelid` =  '".$idsub."', `imageurl` = '". $image . "' WHERE  `id` =".$id." LIMIT 1";
		echo $query;
		mysql_query($query);
			
		print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6; URL=admin_article.php?list=1\">";
		print "Wijziging succesvol.<br>";
		print "<blink>U wordt doorgestuurd...</blink>";
	}
	
	$articleid = $_GET['id'];
	
	$query = mysql_query("SELECT * FROM artikelen WHERE id = '" . $articleid ."'");
	while($result = mysql_fetch_object($query))
	{
	?>
	 	
       <form method="post" action="admin_article.php?editart=1&start=1&id=<? print $result->id; ?>" name="klant_wijzig">
        <table width="100%" border="0">
			<tr>
				<td width="25%"><b>Id:</b></td>
				<td width="75%"><input name="id" type="text" value="<? print $articleid; ?>" size="5" disabled></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Omschrijving:</b></td>
				<td><input name="omschrijving" type="text" value="<? print $result->omschrijving; ?>"></td>
			</tr>
			<tr>
				<td><b>Bedrag:</b></td>
				<td><input name="kopje" type="text" value="<? print $result->bedrag; ?>"></td>
			</tr>
			<tr>
				<td><b>Subartikel:</b></td>
				<td>
				<select name="subartikel">
				<?
                $query = mysql_query("SELECT * FROM subartikelen");
				while($result = mysql_fetch_object($query))
				{
				?>
					<option><? print $result->kopje; ?></option>
                <?
				}
				?>
                </select>
                </td>
			</tr>
            <tr>
				<td><b>Image:</b></td>
				<td><input name="image" type="text" value="<? print $result->imageurl; ?>"></td>
			</tr>
            <tr>
				<td></td>
				<td><input name="submit" type="submit" value="Edit"></td>
			</tr>
		</table>
		</form>
     <?
	 }
}

if($_GET['newsub'])
{
	if($_GET['start'])
	{
		$omschrijving = $_POST['omschrijving'];
		$kopje = $_POST['kopje'];
		
		//$artikel->addsub($omschrijving, $kopje);
		mysql_query("INSERT INTO subartikelen (omschrijving, kopje) 
		VALUES('".$omschrijving."', '".$kopje."')");
		
		print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"1; URL=admin_article.php?list=1\">";
		print "Wijziging succesvol.<br>";
		print "<blink>U wordt doorgestuurd...</blink>";
	}
	?>
	 <form method="post" action="admin_article.php?newsub=1&start=1" name="klant_wijzig">
        <table width="100%" border="0">
			<tr>
				<td width="25%"><b>Id:</b></td>
				<td width="75%"><input name="id" type="text" value="" size="5" disabled></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Omschrijving:</b></td>
				<td><input name="omschrijving" type="text" value=""></td>
			</tr>
            <tr>
				<td><b>Subartikel:</b></td>
				<td><input name="kopje" type="text" value=""></td>
			</tr>
                        <tr>
				<td></td>
				<td><input name="submit" type="submit" value="Add"></td>
			</tr>
		</table>
		</form>
      <?
}

if($_GET['newart'])
{
	if($_GET['start'])
	{
		$omschrijving = $_POST['omschrijving'];
		$bedrag = $_POST['bedrag'];
		$subartikel = $_POST['subartikel'];
		$image = $_POST['image'];
		
		$query = mysql_query("SELECT * FROM subartikelen WHERE kopje = '" . $subartikel ."'");
		while($result = mysql_fetch_object($query))
		{
			$idsub = $result->id;
		}
		
		
		mysql_query("INSERT INTO artikelen (omschrijving, bedrag, subarticleid, imageurl) 
		VALUES('".$omschrijving."', '".$bedrag."','".$idsub."',' " .$image."')");
		
	}
	
	?>
    	 <form method="post" action="admin_article.php?newart=1&start=1" name="klant_wijzig">
        <table width="100%" border="0">
			<tr>
				<td width="25%"><b>Id:</b></td>
				<td width="75%"><input name="id" type="text" value="" size="5" disabled></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Omschrijving:</b></td>
				<td><input name="omschrijving" type="text" value=""></td>
			</tr>
			<tr>
				<td><b>Bedrag:</b></td>
				<td><input name="bedrag" type="text" value=""></td>
			</tr>
			<tr>
				<td><b>Subartikel:</b></td>
				<td>
                <select name="subartikel">
				
				<?
                $query = mysql_query("SELECT * FROM subartikelen");
				while($result = mysql_fetch_object($query))
				{
				?>
					<option><? print $result->kopje; ?></option>
                <?
				}
				?>
                </select>
                </td>
			</tr>
            <tr>
				<td><b>Image:</b></td>
				<td><input name="image" type="text" value=""></td>
			</tr>
                        <tr>
				<td></td>
				<td><input name="submit" type="submit" value="Add"></td>
			</tr>
		</table>
		</form>
    <?
}



//listview van alle klanten
if($_GET['list'])
{
	echo "<title>Admin, list artikelen.</title>";
	?><head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" href="../css/form.css" type="text/css" />
            </head>
            
        <a href="admin_article.php?newart=1"> nieuwe artikel </a>
                <table width="%" border="0">
		<tr>
			<td width="5%"><b>Nr</b></td>
			<td width="50%"><b>Omschrijving</b></td>
			<td width="15%"><b>Prijs</b></td>
            <td width="15%"><b>Sub-id</b></td>
		</tr>
		<tr>
			<td colspan="5"><hr size="1" width="100%"></td>
		</tr>
		<?
		$query = mysql_query("SELECT * FROM artikelen"); 
		while($result = mysql_fetch_object($query))
		{
		?>
		<tr>
			<td><? print $result->id; ?></a></td>
			<td><? print $result->omschrijving; ?></td>
			<td><? print "€".$result->bedrag; ?></td>
            <td><? print $result->subarticleid; ?></td>
			<td>
				<a href="admin_article.php?editart=1&id=<? print $result->id; ?>">
				<img src="../images/edit.jpg" border="0"></a> 
				<a href="admin_article.php?deleteclick=1&id=<? print $result->id; ?>" onClick="return confirm('Wilt u zeker deze artikel verwijderen?')">
				<img src="../images/delete.jpg" border="0"></a>
			</td>
		</tr>
        
		<?
		}
		$result = mysql_num_rows($query);  
		if(!$result)
		{
		?>
		<tr>
			<td colspan="5">Geen artikelen.</td>
		</tr>
		<?
		}
		?>
	</table>
    
    <br /><br />
    <a href="admin_article.php?newsub=1"> nieuwe subartikel </a>
    <table width="%" border="0">
		<tr>
			<td width="5%"><b>Nr</b></td>
			<td width="50%"><b>Omschrijving</b></td>
			<td width="15%"><b>Kopje</b></td>
		</tr>
		<tr>
			<td colspan="5"><hr size="1" width="100%"></td>
		</tr>
		<?
		$query = mysql_query("SELECT * FROM subartikelen"); 
		while($result = mysql_fetch_object($query))
		{
		?>
		<tr>
			<td><? print $result->id; ?></a></td>
			<td><? print $result->omschrijving; ?></td>
			<td><? print $result->kopje; ?></td>
			<td>
				<a href="admin_article.php?editsub=1&id=<? print $result->id; ?>">
				<img src="../images/edit.jpg" border="0"></a> 
				<a href="admin_article.php?deleteclicksub=1&id=<? print $result->id; ?>" onClick="return confirm('Wilt u zeker deze artikel verwijderen?')">
				<img src="../images/delete.jpg" border="0"></a>
			</td>
		</tr>
        
		<?
		}
		$result = mysql_num_rows($query);  
		if(!$result)
		{
		?>
		<tr>
			<td colspan="5">Geen subartikelen.</td>
		</tr>
		<?
		}
		?>
	</table>
	<?
}
?>